<include file="Public/head" />
<style type="text/css">
    .lot_input{border: 1px solid #d7d7d7;float: left;height: 24px;line-height: 24px;margin: 0 10px 10px 0;text-align: center;width: 150px;}
    #lot_type,#lot_status{
        -moz-appearance: none;background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}/paimai/yunying/images/sanjiao.jpg") no-repeat scroll 110px 5px;border: 1px solid #d7d7d7;color: #666;
        float: left;font-family: "微软雅黑";height: 26px;line-height: 26px;margin: 0 10px 10px 0;text-align: left;width: 130px;}
     .xiaci1{
        background: rgba(0, 0, 0, 0) url("{:get_style_cdnurl()}/paimai/yunying/images/yun_tubiao1.jpg") no-repeat scroll 130px 4px;border: 1px solid #d7d7d7;float: left;
        height: 24px;line-height: 24px;margin-right: 10px;padding-left: 10px;text-align: left;width: 140px;}
    .table thead tr > td
    ,.table tbody tr>td {text-align: center;vertical-align:middle; }
    .chenggong1 .paidan{padding-top: 20px;}
    .paidan h3{font-size:24px;color:#000;margin-bottom: 20px;}
    .shenhei-btn{margin-top:30px;}
    .tanShang .daiJingW{padding: 20px 0 0 10px;}
    .tanShang6 .cardealer-zhanghao{width:560px;}
    .tanShang6{height:260px;}
    .tanShang6 .lottory {height:30px; line-height:30px;margin:0; text-align:left; overflow:hidden;}
    .tanShang6 .lottory span{width:90px; text-align:right;float:left; display:block;}
    .tanShang6 .lottory em{color:#20ab4f;padding:0;font-size:14px;padding-left:5px;}
</style>
</head>
<include file="Public/common_header" />
<div class="mian">
    <include file="Public/sidebar"  menu="hdgl" />
    <div class="mianR">
        <h3 class="cha">活动管理</h3>
        <div class="lottory yuSuo clearfix">
            <form id="searchFrom">
                <input type="text" name="lot_id" placeholder="请输入活动ID" class="lot_input"/>
                <input type="text" name="lot_name" placeholder="请输入名称" class="lot_input"/>
                <select name="lot_type" id="lot_type">
                    <option value="">全部类型</option>
                    <option value="1">注册有礼</option>
                </select>
                <select name="lot_status" id="lot_status">
                    <option value="">全部状态</option>
                    <option value="1">待上线</option>
                    <option value="2">进行中</option>
                    <option value="3">已结束</option>
                    <option value="4">已下线</option>
                </select>
                <input type="text" name="start_time" placeholder="开始时间" value="" class="xiaci1 xin-text" id="lottory_start_time" readonly>
                <input type="text" name="end_time"  placeholder="结束时间" value="" class="xiaci1 xin-text" id="lottory_end_time" readonly />
                <input type="button" value="筛选" name="lottory_search" class="suoSou" />
                <input type="button" value="全部" onclick="location.href = '/Lottory/index'" class="suoSou" name="lottory_search"/>
            </form>
            <div style="float:left;width:100%;height:30px;">
                <input type="button" value="新建活动" onclick="location.href = '/Lottory/lottoryCreate'" class="suoSou" style="width:80px;"/>
            </div>
        </div>
        <!--div class="yunBei" style="z-index:999998"></div-->
        <div class="yuList">
            <div class="listBox" id="listBox"></div>
        </div>
    </div>
    <div class="clear"></div>
    <!--充值弹出窗口-->
        <div class="yunBei run_lottery" style="display:none"></div>
        <form id="add_fm">
            <div class="tanShang tanShang6 add_tanShang" style="display:none">
                <h3>开奖信息</h3>
                <ul class="daiJingW">
                    <li class="lottory">
                        <span>上证指数：</span>
                        <input type="text" name="sse" placeholder="请输入上证指数"  />          
                    </li>
                    <li class="lottory">
                        <span>深证指数： </span>
                        <input type="text" name="szs" placeholder="请输入深证指数"  />     
                    </li>
                    <li class="lottory">
                        <span>中奖号码：</span><em id="lottory_win_num"></em>
                    </li>
                    <li class="clearfix">
                        <span>奖券数量：</span><em id="lottory_ticket_nums"></em>
                    </li>
                    <li class="clearfix">
                        <input type="hidden" name="lottory_id">
                        <input type="button" value="确定" class="queding" id="qd_run_lottery"/>          
                        <input type="button" value="取消" class="quxiao" />          
                    </li>
                </ul>
            </div>
        </form>
    </div>
    
    <script type="text/javascript">
        function validateIndex(num){
            return /^\d{4}.\d{2}$/.test(num);
        }
        $("input[name='sse']").val("");
        $("input[name='szs']").val("");
        /**
         * 上证指数
         */
       $("input[name='sse']").keyup(function(){
           var sse = $(this).val();
           if(!validateIndex(sse)){
               return;
           }
           var lottory_ticket_nums = $("#lottory_ticket_nums").html();
           var szs = $("input[name='szs']").val();
           if($.trim(sse) == ''){
               shibai_alert("上证指数不能为空");
               return false;
           }
           if(!validateIndex(sse)){
               shibai_alert("上证指数格式不正确");
               return false;
           }
           if($.trim(szs) == ''){
//               shibai_alert("深证指数不能为空");
               return false;
           }
           if(!validateIndex(szs)){
//               shibai_alert("深证指数格式不正确");
               return false;
           }
           var post_data = {
               'lottory_ticket_nums':lottory_ticket_nums,
               'sse':sse,
               'szs':szs
           };
           $.post("/Lottory/getLottoryWinNum",post_data,function(data){
               $("#lottory_win_num").html(data.win_num);
           },"JSON");
       });
       /**
        * 深证指数
        */
       $("input[name='szs']").keyup(function(){
           var szs = $(this).val();
           if(!validateIndex(szs)){
               return;
           }
           var lottory_ticket_nums = $("#lottory_ticket_nums").html();
           var sse = $("input[name='sse']").val();
           if($.trim(szs) == ''){
               shibai_alert("深证指数不能为空");
               return false;
           }
           if(!validateIndex(szs)){
               shibai_alert("深证指数格式不正确");
               return false;
           }
           if($.trim(sse) == ''){
//               shibai_alert("上证指数不能为空");
               return false;
           }
           if(!validateIndex(sse)){
//               shibai_alert("上证指数格式不正确");
               return false;
           }
           var post_data = {
               'lottory_ticket_nums':lottory_ticket_nums,
               'sse':sse,
               'szs':szs
           };
           $.post("/Lottory/getLottoryWinNum",post_data,function(data){
               $("#lottory_win_num").html(data.win_num);
           },"JSON");
       });
       
       /**
        * 开奖 -- 填写上证、深证指数
        * @param int lot_id
        * @returns 
        */
       function run_lottery(lot_id) {
           $.post('/Lottory/getLottoryDetail', {'lot_id': lot_id}, function (data) {
               if(data.lottory_win_num > 0){
                   $("#lottory_win_num").html(data.lottory_win_num);
               }else{
                   $("#lottory_win_num").html('待开奖');
               } 
               $("#lottory_ticket_nums").html(data.lottory_ticket_nums);
               $("input[name='lottory_id']").val(lot_id);
               $('.run_lottery,.add_tanShang').show();
           }, 'json');
       }
    /**
     * 确定开奖
     */
    $("#qd_run_lottery").on("click", function () {
        var sse = $("input[name='sse']").val();
        if($.trim(sse) == ''){
            shibai_alert("上证指数不能为空");
            return false;
        }
        if(!validateIndex(sse)){
            shibai_alert("上证指数格式不正确");
            return false;
        }
        var szs = $("input[name='szs']").val();
        if($.trim(szs) == ''){
            shibai_alert("深证指数不能为空");
            return false;
        }
        if(!validateIndex(szs)){
            shibai_alert("深证指数格式不正确");
            return false;
        }
        var lottory_id = $("input[name='lottory_id']").val();
        var lottory_win_num = $("#lottory_win_num").html();
        if(lottory_win_num == '待开奖'){
            shibai_alert("请先获取中奖号码");
            return false;
        }
        var post_data = {
            'sse':sse,
            'szs':szs,
            'lottory_id': lottory_id,
            'lottory_win_num': lottory_win_num
        };
        var btn_obj = $(this);
//        btn_obj.val("开奖中...").attr("disabled", 'disabled');
        $.post("/Lottory/runLottory", post_data, function (data) {
            try {
                if (data.code == 200) {
                    delay_alert('开奖成功!', 300);
                    setTimeout(function () {
                        btn_obj.val("确定").removeAttr("disabled style");
                        window.location.reload();
                    }, 400);
                } else {
                    btn_obj.val("确定").removeAttr("disabled style");
                    delay_alert(data.msg, 300);
                }
            } catch (e) {
                btn_obj.val("确定").removeAttr("disabled style");
                delay_alert('开奖失败!', 300);
            }
        }, 'json');
    });
        
        //获取url中的参数
        function getUrlParam(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
            var r = window.location.search.substr(1).match(reg);  //匹配目标参数
            if (r != null)
                return unescape(r[2]);
            return null; //返回参数值
        }
        get_list();
        function get_list() {
            var url = mkUrl();
            var p = getUrlParam('p');
            if (p != null) {
                var purl = "?p=" + p;
            } else {
                var purl = "?p=1";
            }
            $.get("/Lottory/lottoryList" + purl, url, function (data) {
                $("#listBox").html(data);
            }, "html");
        }
        function get_page(p) {
            var url = mkUrl();
            $.get("/Lottory/lottoryList/" + encodeURI("p/" + p), url, function (data) {
                $("#listBox").html(data);
            }, "html");
        }

        $("input[name='lottory_search']").click(function () {
            get_list();
        });
        function mkUrl() {
            var url = "";
            var lot_id = $("input[name='lot_id']").val();
            var lot_name = $("input[name='lot_name']").val();
            var lot_type = $("#lot_type").val();
            var lot_status = $("#lot_status").val();
            var start_time = $("input[name='start_time']").val();
            var end_time = $("input[name='end_time']").val();
            if (lot_id) {
                url += '&lot_id=' + lot_id;
            }
            if (lot_name) {
                url += '&lot_name=' + lot_name;
            }
            if (lot_type) {
                url += '&lot_type=' + lot_type;
            }
            if (lot_status) {
                url += '&lot_status=' + lot_status;
            }
            if (start_time) {
                url += '&start_time=' + start_time;
            }
            if (end_time) {
                url += '&end_time=' + end_time;
            }
            return url;
        }
    
    function confirm_popup(lot_id, lot_status,lot_name) {
        if (lot_status == '2') {
            msg = '确认上线活动<br/>'+'"'+lot_name+'"';
            htext = "活动上线";
        } else {
            msg = '确认下线活动<br/>'+'"'+lot_name+'"';
            htext = "活动下线";
        }
        text = '<div style="color:red;font-size:16px;">' + msg + '</div>';
        var html = '<div class="chenggong1">\n\
                    <span class="paidan"><h3>' + htext + '</h3>' + text + '</span>\n\
                    <div class="shenhei-btn"><input type="button" value="确定" class="determine" />\n\
                    <input type="button" value="取消" class="cancel" onclick="colse_hide()" />\n\
                    </div></div>';
        $(".yunBei").css("display", "block");
        $(document.body).append(html);
        $(".chenggong1").fadeIn();
        confirm(lot_id, lot_status);
    }
    function confirm(lot_id, lot_status) {
        $('.determine').click(function () {
            colse_hide();
            change_lottory_status(lot_id, lot_status);
        });
    }
    /**
    * 上下、下线操作
    * @param {type} c_id
    * @param {type} status
    * @returns {Boolean}
    */
   function change_lottory_status(lot_id, lot_status) {
       var post_data = {lot_id: lot_id, lot_status: lot_status};
       $.post('/Lottory/changeLottoryStatus', post_data, function (res) {
           if (res.code == 200) {
               delay_alert('操作成功!');
               setTimeout(function () {
                   window.location.reload();
               }, 500);
           } else {
               delay_alert(res.msg);
           }
       }, 'json');
       return false;
   }
    
    $("#lottory_start_time").ymdateplugin({
//        showTimePanel: true,
//        changeMonth: true,
//        changeYear: true
    });
    $("#lottory_end_time").ymdateplugin({
//        showTimePanel: true,
//        changeMonth: true,
//        changeYear: true
    });

    </script>
    <include file="Public/foot" />